@echo off
echo ==========================================
echo 监控脚本执行
echo ==========================================

:loop
cls
echo 当前时间: %date% %time%
echo.
echo === 日志文件内容 ===
if exist "D:\wwwroot\yingyang\runtime\auto_process_dish_info.log" (
    echo 最新的日志内容:
    powershell "Get-Content 'D:\wwwroot\yingyang\runtime\auto_process_dish_info.log' -Tail 10"
) else (
    echo 日志文件不存在
)

echo.
echo === 数据库状态 ===
cd /d D:\wwwroot\yingyang
php -r "
<?php
try {
    \$config = ['hostname'=>'127.0.0.1', 'database'=>'yingyang', 'username'=>'root', 'password'=>'root', 'charset'=>'utf8mb4'];
    \$dsn = 'mysql:host=' . \$config['hostname'] . ';dbname=' . \$config['database'] . ';charset=' . \$config['charset'];
    \$pdo = new PDO(\$dsn, \$config['username'], \$config['password']);
    
    \$stmt = \$pdo->query('SELECT COUNT(*) as total FROM fa_food_dish');
    \$total = \$stmt->fetch(PDO::FETCH_ASSOC);
    
    \$stmt = \$pdo->query('SELECT COUNT(*) as processed FROM fa_food_dish WHERE ai_called = 1');
    \$processed = \$stmt->fetch(PDO::FETCH_ASSOC);
    
    echo '总菜品数: ' . \$total['total'] . PHP_EOL;
    echo '已处理数: ' . \$processed['processed'] . PHP_EOL;
} catch (Exception \$e) {
    echo '查询失败: ' . \$e->getMessage() . PHP_EOL;
}
?>
"

echo.
echo 等待10秒后刷新... (按Ctrl+C退出)
timeout /t 10 /nobreak >nul
goto loop